<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>登录 - 文库管理系统</title>
    <link rel="stylesheet" href="__PUBLIC__/admin/layui/css/layui.css">
    <link rel="stylesheet" href="__PUBLIC__/admin/static/css/style.css">
    <link rel="icon" href="__PUBLIC__/admin/static/image/code.png">
</head>
<body class="login-body body">

<div class="login-box">
    <form class="layui-form layui-form-pane" method="get" action="">
        <div class="layui-form-item">
            <h3>文库管理系统</h3>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">账号：</label>
            <div class="layui-input-inline">
                <input type="text" name="username" class="layui-input" lay-verify="username" placeholder="管理员账号" autocomplete="on" maxlength="20"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码：</label>
            <div class="layui-input-inline">
                <input type="password" name="password" class="layui-input" lay-verify="password" placeholder="登录密码" maxlength="20"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">验证码：</label>
            <div class="layui-input-inline">
                <input type="number" name="verify_code" class="layui-input" lay-verify="verify_code" placeholder="验证码" maxlength="4"/>
                <img title="{$Think.lang.refresh_verify_code}" class="verify_img" src="{:U('index/verify_code', array('t'=>time()))}" />
            </div>
        </div>
        <div class="layui-form-item">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="sub"  style="width:300px">立即登录</button>
        </div>
    </form>
</div>
<script type="text/javascript" src="__PUBLIC__/admin/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form', 'layer'], function () {
        // 操作对象
        var form = layui.form, layer = layui.layer, $ = layui.jquery;

        // 验证
        form.verify({
            account: function (value) {
                if (value == "") {
                    return "请输入账号";
                }
            },
            password: function (value) {
                if (value == "") {
                    return "请输入密码";
                }
            },
            verify_code: function (value) {
                if (value == "") {
                    return "请输入验证码";
                }
            }
        });
        //重置验证码
        $(function(){
		    if(self != top){
		        top.location = self.location;
		    }
		    $(".verify_img").click(function(){
		        var timenow = new Date().getTime();
		        $(this).attr("src","{:U('index/verify_code')}&"+timenow)
		    });
		});

        // 提交
         form.on('submit(sub)', function (data) {
            // 提交到方法 默认为本身
            $.post("{:U('index/login')}",data.field,function(res){
                if(res.status.status ==	 1){
                    layer.msg(res.status.info,{time:1800},function(){
                    	location.href = res.status.url;
                    });
                }else{
                    layer.msg(res.status.info,{time:1800});
                    $('.verify_img').click();
                }
            });
            return false;
        });
    })
</script>
</body>
</html>